import { requestClient } from '#/api/request';

const baseWeddingUrl='/wedding/resource/dashboard'
import type {
  DashboardStatistics,
  BookingTrend,
  ServiceDistribution,
  ResourceUtilization,
  TodoItem,
  PageResult,
} from './types';

// ==================== 统计数据接口 ====================

/** 获取仪表板统计数据 */
export function getDashboardStatistics() {
  return requestClient.get<DashboardStatistics>(
    baseWeddingUrl+'/statistics',
  );
}

/** 获取预约趋势数据 */
export function getBookingTrend(params?: {
  startDate?: string;
  endDate?: string;
  interval?: 'day' | 'week' | 'month';
}) {
  return requestClient.get<BookingTrend[]>(  baseWeddingUrl+'/booking-trend', {
    params,
  });
}

/** 获取服务分布数据 */
export function getServiceDistribution(params?: {
  startDate?: string;
  endDate?: string;
}) {
  return requestClient.get<ServiceDistribution[]>(
     baseWeddingUrl+'/service-distribution',
    {
      params,
    },
  );
}

/** 获取资源利用率数据 */
export function getResourceUtilization(params?: {
  resourceType?: 'dress' | 'artist' | 'photographer' | 'all';
  startDate?: string;
  endDate?: string;
}) {
  return requestClient.get<ResourceUtilization[]>(
      baseWeddingUrl+'/resource-utilization',
    {
      params,
    },
  );
}

/** 获取待办事项列表 */
export function getTodoList(params?: {
  type?: string;
  status?: 'pending' | 'completed';
  pageNo?: number;
  pageSize?: number;
}) {
  return requestClient.get<PageResult<TodoItem>>(  baseWeddingUrl+'/todos', {
    params,
  });
}

/** 完成待办事项 */
export function completeTodo(todoId: number) {
  return requestClient.put(  baseWeddingUrl+`/todos/${todoId}/complete`);
}

/** 获取最近订单 */
export function getRecentOrders(limit: number = 10) {
  return requestClient.get( baseWeddingUrl+'/recent-orders', {
    params: { limit },
  });
}

/** 获取营收趋势 */
export function getRevenueTrend(params?: {
  startDate?: string;
  endDate?: string;
  interval?: 'day' | 'week' | 'month';
}) {
  return requestClient.get<
    Array<{
      date: string;
      revenue: number;
      orderCount: number;
    }>
  >(baseWeddingUrl+'/revenue-trend', {
    params,
  });
}

/** 获取客户满意度数据 */
export function getCustomerSatisfaction(params?: {
  startDate?: string;
  endDate?: string;
}) {
  return requestClient.get<{
    averageRating: number;
    totalRatings: number;
    ratingDistribution: Array<{
      rating: number;
      count: number;
      percentage: number;
    }>;
  }>(baseWeddingUrl+'/customer-satisfaction', {
    params,
  });
}

/** 获取热门服务 */
export function getPopularServices(limit: number = 5) {
  return requestClient.get<
    Array<{
      serviceType: string;
      serviceName: string;
      bookingCount: number;
      revenue: number;
    }>
  >(baseWeddingUrl+'/popular-services', {
    params: { limit },
  });
}

